﻿using System.Linq;
using System.Windows.Forms;

namespace OpenLab.UI.Helper
{
    class InputLanguageHelper
    {
        readonly InputLanguage _arabicInput;
        readonly InputLanguage _englishInput;


        public InputLanguageHelper()
        {
            _arabicInput = GetInputLanguageByName("arabic");
            _englishInput = GetInputLanguageByName("english");
        }

        public void SetKeyboardLayout(InputLanguage layout)
        {
            InputLanguage.CurrentInputLanguage = layout;
        }


        public static InputLanguage GetInputLanguageByName(string inputName)
        {
            return InputLanguage.InstalledInputLanguages.Cast<InputLanguage>().FirstOrDefault(lang => lang.Culture.EnglishName.ToLower().StartsWith(inputName));
        }

        public void LoadArabicKeyboardLayout()
        {
            InputLanguage.CurrentInputLanguage = _arabicInput ?? InputLanguage.DefaultInputLanguage;
        }

        public void LoadEnglishKeyboardLayout()
        {
            InputLanguage.CurrentInputLanguage = _englishInput ?? InputLanguage.DefaultInputLanguage;
        }
    }
}
